﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Code;
using System.Data;

namespace E2_WEBSITE.Code.CD_DVD
{
    public class CDDataAccess
    {
        DataProvider m_DataProvider = DataProvider.GlobalDataProvider;
        
        public List<string> GetListSpeedByManufactureName(string sManufacture)
        {
            List<string> lst = new List<string>();
            string sSql = "select distinct TOCDO from CD_DVD,SAN_PHAM,NHA_SAN_XUAT where SAN_PHAM.idNSX = NHA_SAN_XUAT.id AND NHA_SAN_XUAT.TenNSX = '" + sManufacture
           + "' AND SAN_PHAM.id=CD_DVD.id";

            DataTable dt = m_DataProvider.ExecuteQueryDataTable(sSql);
            if (dt != null)
            {
                int iCount = dt.Rows.Count;
                for (int i = 0; i < iCount; i++)
                {
                    lst.Add(dt.Rows[i][0].ToString());
                }
            }
            return lst;
        }

        public List<string> GetProductByManufactureAndSpeed(string sManufacture,string sSpeed)
        {
            List<string> lst = new List<string>();
            string sSql = "select distinct TENSANPHAM from CD_DVD,SAN_PHAM,NHA_SAN_XUAT where SAN_PHAM.idNSX = NHA_SAN_XUAT.id AND NHA_SAN_XUAT.TenNSX = '" + sManufacture
           + "'AND TOCDO='" + sSpeed +"' AND SAN_PHAM.id=CD_DVD.id";

            DataTable dt = m_DataProvider.ExecuteQueryDataTable(sSql);
            if (dt != null)
            {
                int iCount = dt.Rows.Count;
                for (int i = 0; i < iCount; i++)
                {
                    lst.Add(dt.Rows[i][0].ToString());
                }
            }
            return lst;
        }

        public int GetProductIDByManuAndSpeedAndProName(string sManufacture,string sSpeed,string sProName)
        {
            int iId = -1;
            string sSql = "select distinct SAN_PHAM.ID from CD_DVD,SAN_PHAM,NHA_SAN_XUAT where SAN_PHAM.idNSX = NHA_SAN_XUAT.id AND NHA_SAN_XUAT.TenNSX = '" + sManufacture
           + "'AND TOCDO='" + sSpeed + "'AND TENSANPHAM='" + sProName+"' AND SAN_PHAM.id=CD_DVD.id";

            DataTable dt = m_DataProvider.ExecuteQueryDataTable(sSql);
            if (dt != null)
            {
                if (dt.Rows.Count > 0)
                    iId = int.Parse(dt.Rows[0][0].ToString());
            }
            return iId;
        }
    }
}
